package com.ruoyi.alarm.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.alarm.domain.AlarmReport;
import com.ruoyi.alarm.service.IAlarmReportService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 焊接质量追溯与分析Controller
 * 
 * @author ruoyi
 * @date 2023-02-11
 */
@Controller
@RequestMapping("/alarm/report")
public class AlarmReportController extends BaseController
{
    private String prefix = "alarm/report";

    @Autowired
    private IAlarmReportService alarmReportService;

    @RequiresPermissions("alarm:report:view")
    @GetMapping()
    public String report()
    {
        return prefix + "/report";
    }

    /**
     * 查询焊接质量追溯与分析列表
     */
    @RequiresPermissions("alarm:report:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AlarmReport alarmReport)
    {
        startPage();
        List<AlarmReport> list = alarmReportService.selectAlarmReportList(alarmReport);
        return getDataTable(list);
    }

    /**
     * 导出焊接质量追溯与分析列表
     */
    @RequiresPermissions("alarm:report:export")
    @Log(title = "焊接质量追溯与分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AlarmReport alarmReport)
    {
        List<AlarmReport> list = alarmReportService.selectAlarmReportList(alarmReport);
        ExcelUtil<AlarmReport> util = new ExcelUtil<AlarmReport>(AlarmReport.class);
        return util.exportExcel(list, "焊接质量追溯与分析数据");
    }

    /**
     * 新增焊接质量追溯与分析
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存焊接质量追溯与分析
     */
    @RequiresPermissions("alarm:report:add")
    @Log(title = "焊接质量追溯与分析", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AlarmReport alarmReport)
    {
        return toAjax(alarmReportService.insertAlarmReport(alarmReport));
    }

    /**
     * 修改焊接质量追溯与分析
     */
    @RequiresPermissions("alarm:report:edit")
    @GetMapping("/edit/{alarmGroup}")
    public String edit(@PathVariable("alarmGroup") String alarmGroup, ModelMap mmap)
    {
        AlarmReport alarmReport = alarmReportService.selectAlarmReportByAlarmGroup(alarmGroup);
        mmap.put("alarmReport", alarmReport);
        return prefix + "/edit";
    }

    /**
     * 修改保存焊接质量追溯与分析
     */
    @RequiresPermissions("alarm:report:edit")
    @Log(title = "焊接质量追溯与分析", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AlarmReport alarmReport)
    {
        return toAjax(alarmReportService.updateAlarmReport(alarmReport));
    }

    /**
     * 删除焊接质量追溯与分析
     */
    @RequiresPermissions("alarm:report:remove")
    @Log(title = "焊接质量追溯与分析", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(alarmReportService.deleteAlarmReportByAlarmGroups(ids));
    }
}
